package com.wgj.android.adapter;

import android.graphics.drawable.Drawable;
import android.support.annotation.NonNull;
import android.support.v7.widget.RecyclerView;
import android.view.View;

import com.jiaai.xui.XUI;
import com.jiaai.xui.adapter.XRecyclerViewAdapter;
import com.jiaai.xui.adapter.XViewHolder;
import com.jiaai.xui.utils.XResourcesUtils;
import com.jiaai.xui.utils.http.HttpCallBack;
import com.jiaai.xui.utils.http.XHttp;
import com.jiaai.xui.view.widget.CircleImageView;
import com.jiaai.xui.view.widget.XToast;
import com.wgj.android.R;
import com.wgj.android.entity.BankInfo;
import com.wgj.android.http.WGJAPI;
import com.wgj.android.ui.activity.MyBankActivity;
import com.wgj.android.utils.HideDataUtil;

import java.util.List;

/**
 * Created by Administrator on 2017/12/10.
 */

public class BankAdapter extends XRecyclerViewAdapter<BankInfo>{
    public BankAdapter(@NonNull RecyclerView mRecyclerView, List<BankInfo> dataLists) {
        super(mRecyclerView, dataLists, R.layout.item_bank_info);
    }

    @Override
    protected void bindData(XViewHolder holder, final BankInfo bankInfo, final int i) {
        int iconId= XResourcesUtils.getDrableId("icon_bank_"+bankInfo.getBank_code());
        CircleImageView circleImageView=holder.getView(R.id.bankIcon);
        circleImageView.setImageDrawable(XUI.getDrawable(iconId));
        holder.setText(R.id.bankName,bankInfo.getBank_name());
        holder.setText(R.id.number, HideDataUtil.hideCardNo(bankInfo.getBank_no()));
        holder.setOnClickListener(R.id.tv_unbind, new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                XHttp.obtain().get(WGJAPI.BASEURL + "bank/delete?id=" + bankInfo.getId(), null, new HttpCallBack<String>() {
                    @Override
                    public void onSuccess(String s) {
                        dataLists.remove(i);
                        //notifyDataSetChanged();
                    }

                    @Override
                    public void onFailed(int i, String s, boolean b) {
                        XToast.error("异常");
                    }
                });
            }
        });
    }
}
